<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /**
         * 判断子序列
           输入：s = "abc", t = "ahbgdc"
           输出：true
           解释：判断s是否为t的子序列，是则返回true

           分析：双指针---》两个指针遍历，查找s的字符是否能够按顺序在t中出现
        */
        /* 
            时间：O(n)
            空间：O(1)
        */
        // 动态规划
        var maxSubArray = function(s, t) {
            let len1 = s.length;
            let len2 = t.length;
            let sIndex = 0
            for (let j = 0; sIndex < len1, j < len2; j++) {
                if (s[sIndex] === t[j]) {
                  // 如果相等，就让sIndex++，
                  sIndex++
                }
            }
            // sIndex和len1相同意味着s为t的子串
            return sIndex === len1
        };
        console.log(maxSubArray('abc', 'ahbgdc'));
    </script>
</body>

</html>